<?php

namespace App\Modules\Admin\Services\Water\Member;

use App\Exceptions\Exception;
use App\Library\Junda\src\CardService;
use App\Modules\Admin\Entities\Member\UserBankModel;
use App\Modules\Admin\Entities\Member\UserWaterCardModel;
use App\Modules\Admin\Services\BaseService;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class UsersCardService extends BaseService
{
    public function __construct(UserWaterCardModel $model)
    {
        $this->model = $model;
    }
    public function lists(array $params) : array
    {
        //CardService::GetCardList(['size'=>$params['limit'],'page'=>$params['page']]);

//        $params['where_callback'] = function($query) use ($params){
//            $request = request();
//            // 按照名称进行搜索
//            if (!empty($search = $request->input('search', ''))){
//                $query->where('nickname', 'LIKE', '%' . trim($search) . '%');
//            }
//            if (!empty($search = $request->input('search', ''))){
//                $query->where('nickname', 'LIKE', '%' . trim($search) . '%');
//            }
//        };
//

        return parent::lists($params); // TODO: Change the autogenerated stub
    }



    public function create(array $params)
    {
        $cardno = '24120104400';
        $cardmoney = 500;
        $buymoney = 500;
        $res = CardService::ICAccountCharge($cardno,$cardmoney,$buymoney);
        CardService::ICAccountCharge($cardno,$cardmoney,$buymoney);
        return true;
    }
    public function update(array $params)
    {

        DB::beginTransaction();
        try{
            parent::update($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
    /**
     * @param $id
     * @param $uid
     * @return array
     */
    public function find($id,$uid): array
    {

        return [

            'name' => 6,
        ];
    }

}
